package com.obrempon.credit.market.ui.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.obrempon.credit.market.R
import com.obrempon.module.adapter.ObremponRecyclerViewAdapter
import com.obrempon.module.adapter.ObremponViewHolderHelper
import org.json.JSONObject

/**
 * ObremponCredit
 * @Author wwdeng
 * @CreateTime: 2025/3/6 13:33
 * @Annotation：客服列表
 */
class ObremponCustomerAdapter(recyclerView: RecyclerView?) : ObremponRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.obrempon_customer_dialog_item) {
    override fun setItemChildListener(helper: ObremponViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.btnCustomer) //拨号、复制
    }

    override fun fillData(helper: ObremponViewHolderHelper, position: Int, model: JSONObject) {
        helper.setText(R.id.textCustomerValue,model.optString("value"))
        val imgCustomerFun = helper.getImageView(R.id.imgCustomerFun)
        when(model.optString("type")){
            "MOBILE" -> {//电话
                helper.setText(R.id.textCustomerTitle,String.format(mContext.getString(R.string.obrempon_customer_dialog_mobile_title),"${position +1}"))
                helper.setText(R.id.textCustomerFun,mContext.getString(R.string.obrempon_customer_dialog_mobile_dial))
                imgCustomerFun.setImageResource(R.mipmap.obrempon_customer_mobile_call)
            }
            else -> {//邮箱
                helper.setText(R.id.textCustomerTitle,mContext.getString(R.string.obrempon_customer_dialog_email_title))
                helper.setText(R.id.textCustomerFun,mContext.getString(R.string.obrempon_customer_dialog_email_copy))
                imgCustomerFun.setImageResource(R.mipmap.obrempon_customer_email_copy)
            }
        }
        if (position == itemCount - 1){
            helper.setVisibility(R.id.viewCustomerLine, View.INVISIBLE)
        } else {
            helper.setVisibility(R.id.viewCustomerLine, View.VISIBLE)
        }
    }
}